import request from '@/utils/request'
import type { PassTemplate, SettingsField, TemplateListRequest, TemplateListResponse, TemplateInfo } from './passModel'
import type { PageData } from '#/axios'

export function getTemplateList(data: TemplateListRequest):Promise<TemplateListResponse & PageData> {
  return request({    
    url: `/online/pass-generate/pass/list`,
    params: data
  })
}

export function saveTemplate(templateData: PassTemplate):Promise<void> {
  return request({    
    url: `/online/pass-generate/pass/${templateData.passTypeIdentifier}`,
    method: 'POST',
    data: templateData
  })
}

export function saveSettings(settings: SettingsField):Promise<void> {
  return request({
    url: '/pass/save-settings',
    method: 'post',
    data: settings
  })
}
// 0 - 删除失败，需要先新建模板才能删除, 1 - 删除成功
export function deleteTemplate(tempId: number):Promise<0 | 1> {
  return request({
    url: `/online/pass-generate/pass/${tempId}`,
    method: 'DELETE'
  })
}

export function getTemplateInfo(tempId: string):Promise<TemplateInfo> {
  return request({
    url: `/online/pass-generate/pass/${tempId}`,
    method: 'GET'
  })
}

export function updateTemplate(tempId: string, data:PassTemplate) {
  return request({
    url: `/online/pass-generate/pass/${tempId}`,
    method: 'PUT',
    data
  })
}

export function unRegisterTemplate(tempId: number) {
  return request({
    url: `/online/pass-generate/pass/unregister/${tempId}`,
    method: 'POST'
  })
}